package cn.iocoder.yudao.module.vos.controller.admin.marketinglistlog;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.vos.controller.admin.marketinglistlog.vo.*;
import cn.iocoder.yudao.module.vos.dal.dataobject.marketinglistlog.MarketingListLogDO;
import cn.iocoder.yudao.module.vos.service.marketinglistlog.MarketingListLogService;

@Tag(name = "管理后台 - 营销名单日志表（含应答状态）")
@RestController
@RequestMapping("/vos/marketing-list-log")
@Validated
public class MarketingListLogController {

    @Resource
    private MarketingListLogService marketingListLogService;

    @PostMapping("/create")
    @Operation(summary = "创建营销名单日志表（含应答状态）")
    @PreAuthorize("@ss.hasPermission('vos:marketing-list-log:create')")
    public CommonResult<Long> createMarketingListLog(@Valid @RequestBody MarketingListLogSaveReqVO createReqVO) {
        return success(marketingListLogService.createMarketingListLog(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新营销名单日志表（含应答状态）")
    @PreAuthorize("@ss.hasPermission('vos:marketing-list-log:update')")
    public CommonResult<Boolean> updateMarketingListLog(@Valid @RequestBody MarketingListLogSaveReqVO updateReqVO) {
        marketingListLogService.updateMarketingListLog(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除营销名单日志表（含应答状态）")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('vos:marketing-list-log:delete')")
    public CommonResult<Boolean> deleteMarketingListLog(@RequestParam("id") Long id) {
        marketingListLogService.deleteMarketingListLog(id);
        return success(true);
    }

    @DeleteMapping("/delete-list")
    @Parameter(name = "ids", description = "编号", required = true)
    @Operation(summary = "批量删除营销名单日志表（含应答状态）")
                @PreAuthorize("@ss.hasPermission('vos:marketing-list-log:delete')")
    public CommonResult<Boolean> deleteMarketingListLogList(@RequestParam("ids") List<Long> ids) {
        marketingListLogService.deleteMarketingListLogListByIds(ids);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得营销名单日志表（含应答状态）")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('vos:marketing-list-log:query')")
    public CommonResult<MarketingListLogRespVO> getMarketingListLog(@RequestParam("id") Long id) {
        MarketingListLogDO marketingListLog = marketingListLogService.getMarketingListLog(id);
        return success(BeanUtils.toBean(marketingListLog, MarketingListLogRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得营销名单日志表（含应答状态）分页")
    @PreAuthorize("@ss.hasPermission('vos:marketing-list-log:query')")
    public CommonResult<PageResult<MarketingListLogRespVO>> getMarketingListLogPage(
            @Valid MarketingListLogPageReqVO pageReqVO) {
        PageResult<MarketingListLogDO> pageResult = marketingListLogService.getMarketingListLogPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, MarketingListLogRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出营销名单日志表（含应答状态） Excel")
    @PreAuthorize("@ss.hasPermission('vos:marketing-list-log:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportMarketingListLogExcel(@Valid MarketingListLogPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<MarketingListLogDO> list = marketingListLogService.getMarketingListLogPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "营销名单日志表（含应答状态）.xls", "数据", MarketingListLogRespVO.class,
                        BeanUtils.toBean(list, MarketingListLogRespVO.class));
    }

}